package com.example.profile.controller;

import com.example.profile.model.ListConfig;
import com.example.profile.model.MapConfig;
import com.example.profile.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-11-21
 * Time: 17:44
 */
@RestController
@RequestMapping("/request")
public class PropertiesController {
//    这是从properties文件中获取（可以的）
    @Value("${mykey.key1}")
    private String key1;
    @RequestMapping("/key")
    public String key(){
        return "读取到值为：" + key1;
    }



//    这是从yml配置文件中获取(不行)
    @Value("${string.hello}")
    private String hello;
    @RequestMapping("key2")
    public String key2(){
        return "读取配置文件yml中的值为：" + hello;
    }

//    测试配置文件中引号的作用
    @Value("${string.str1}")
    private String str1;
    @Value("${string.str2}")
    private String str2;
    @Value("${string.str3}")
    private String str3;
    @RequestMapping("/readYml")
    public String readYml(){
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
        return str1 + str2 + str3;
    }

//    使用配置文件中的对象
    @Autowired//注入依赖
    private Student student;
    @RequestMapping("/readStudent")
    public String readStudent(){
        return student.toString();
    }

//    在配置文件中使用集合
//    注入依赖
    @Autowired
    private ListConfig listConfig;
    @RequestMapping("/readList")
    public String readList(){
        return listConfig.toString();
    }

//  在配置文件中使用map
    @Autowired
    private MapConfig mapConfig;
    @RequestMapping("/readMap")
    public String readMap(){
        return mapConfig.toString();
    }





}
